/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package example;
import facecat.topin.core.*;
import facecat.topin.btn.*;
import facecat.topin.div.*;

/*
* 布局按钮
*/
public class LayoutButton extends FCButton {
    /*
    * 重绘方法
    */
    public void onPaint(FCPaint paint, FCRect clipRect)
    {
        long drawColor = FCColor.rgb(50, 50, 50);
        if (this == m_native.getHoveredView())
        {
            drawColor = FCColor.rgb(42, 138, 195);
        }
        int width = getWidth(), height = getHeight();
        FCDiv parentDiv = (FCDiv)getParent();
        if(parentDiv.getVScrollBar() != null && parentDiv.getVScrollBar().isVisible()){
            width -= 8;
        }
        FCRect drawRect = new FCRect(2, 2, width - 2, height - 2);
        paint.drawRoundRect(drawColor, 1, 0, drawRect, 8);
        String text = getText();
        FCRect iRect = new FCRect(5, 5, 5 + height - 10, height - 5);
        drawDesignerIcon(paint, text, iRect, 0, drawColor, drawColor);
        FCFont tFont = getFont();
        FCSize tSize = paint.textSize(text, tFont);
        drawText(paint, text, drawColor, tFont, iRect.right + 8, (height - tSize.cy) / 2);
    }

   /*
    * 重绘边线方法
    */
    public void onPaintBorder(FCPaint paint, FCRect clipRect)
    {
    }
    
    /** 
    绘制文字

    @param paint 绘图对象
    @param text 文字
    @param dwPenColor 颜色
    @param font 字体
    @param x 横坐标
    @param y 纵坐标
    */
    public static void drawText(FCPaint paint, String text, long dwPenColor, FCFont font, int x, int y)
    {
           FCSize tSize = paint.textSize(text, font, -1);
           FCRect tRect = new FCRect(x, y, x + tSize.cx, y + tSize.cy);
           paint.drawText(text, dwPenColor, font, tRect, -1);
    }
    
     public static void drawDesignerIcon(FCPaint paint, String cName, FCRect drawRect, int tick, long fillColor, long drawColor)
    {
        FCRect imageRect = drawRect;
        int sub = (drawRect.right - drawRect.left) / 5;
        imageRect.left += sub;
        imageRect.top += sub;
        imageRect.right -= sub;
        imageRect.bottom -= sub;
        if (cName.equals("Button"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            drawText(paint, "ab", drawColor, new FCFont("Default", 14, true, false, false), imageRect.left + 2, imageRect.top + 2);
        }
        else if (cName.equals("Calendar"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.fillRect(FCColor.rgb(255, 80, 80), new FCRect(imageRect.left + 12, imageRect.top + 12, imageRect.left + 17, imageRect.top + 18));
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 2, imageRect.top + 12);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 18, imageRect.right - 2, imageRect.top + 18);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 6, imageRect.top, imageRect.left + 6, imageRect.bottom - 2);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 2);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 18, imageRect.top, imageRect.left + 18, imageRect.bottom - 2);
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 8));
        }
        else if (cName.equals("CheckBox"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            FCRect innerRect = imageRect;
            innerRect.left += 3;
            innerRect.top += 3;
            innerRect.right -= 3;
            innerRect.bottom -= 3;
            paint.fillRect(fillColor, innerRect);
        }
        else if (cName.equals("Div"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
        }else if (cName.equals("Blank"))
        {
            paint.drawRect(fillColor, 1, 1, imageRect);
        }
        else if (cName.equals("Label"))
        {
            drawText(paint, "A", fillColor, new FCFont("Default", 24, true, false, false), imageRect.left + 4, imageRect.top);
        }
        else if (cName.equals("LinkLabel"))
        {
            drawText(paint, "A", fillColor, new FCFont("Default", 24, true, false, false), imageRect.left + 4, imageRect.top);
            paint.drawLine(fillColor, 2, 0, imageRect.left + 4, imageRect.bottom + 5, imageRect.right - 4, imageRect.bottom + 5);
        }
        else if (cName.equals("RadioButton"))
        {
            paint.drawEllipse(fillColor, 1, 0, imageRect);
            FCRect innerRect = imageRect;
            innerRect.left += 3;
            innerRect.top += 3;
            innerRect.right -= 3;
            innerRect.bottom -= 3;
            paint.fillEllipse(fillColor, innerRect);
        }
        else if (cName.equals("SplitLayoutDiv"))
        {
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 1);
            paint.drawRect(fillColor, 1, 0, imageRect);
        }
        else if (cName.equals("TextBox"))
        {
            paint.drawRoundRect(fillColor, 1, 0, imageRect, 0);
            drawText(paint, "ab|", fillColor, new FCFont("Default", 14, true, false, false), imageRect.left, imageRect.top + 2);
        }
        else if (cName.equals("ComboBox"))
        {
            paint.fillRect(fillColor, new FCRect(imageRect.right - 5, imageRect.top, imageRect.right, imageRect.top + 5));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left, imageRect.top, imageRect.right, imageRect.top + 6));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 6, imageRect.top + 5, imageRect.right, imageRect.bottom));
            paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 10, imageRect.right - 4, imageRect.top + 10);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 14, imageRect.right - 4, imageRect.top + 14);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 18, imageRect.right - 4, imageRect.top + 18);
        }
        else if (cName.equals("DatePicker"))
        {
            paint.fillRect(fillColor, new FCRect(imageRect.right - 5, imageRect.top, imageRect.right, imageRect.top + 5));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left, imageRect.top, imageRect.right, imageRect.top + 6));
            paint.fillRect(fillColor, new FCRect(imageRect.left + 5, imageRect.top + 5, imageRect.right - 1, imageRect.top + 10));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 5, imageRect.top + 5, imageRect.right, imageRect.bottom));
            paint.fillRect(FCColor.rgb(255, 80, 80), new FCRect(imageRect.left + 14, imageRect.top + 13, imageRect.left + 18, imageRect.top + 17));
            paint.drawLine(fillColor, 1, 0, imageRect.left + 5, imageRect.top + 13, imageRect.right - 1, imageRect.top + 13);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 5, imageRect.top + 17, imageRect.right - 1, imageRect.top + 17);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 5, imageRect.top + 21, imageRect.right - 1, imageRect.top + 21);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 9, imageRect.top + 10, imageRect.left + 9, imageRect.bottom - 1);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 14, imageRect.top + 10, imageRect.left + 14, imageRect.bottom - 1);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 19, imageRect.top + 10, imageRect.left + 19, imageRect.bottom - 1);
        }
        else if (cName.equals("Grid"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 11, imageRect.right - 2, imageRect.top + 11);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 16, imageRect.right - 2, imageRect.top + 16);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 6, imageRect.top, imageRect.left + 6, imageRect.bottom - 2);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 2);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 18, imageRect.top, imageRect.left + 18, imageRect.bottom - 2);
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
        }
        else if (cName.equals("GroupBox"))
        {
            //绘制边线
            FCPoint[] points = new FCPoint[6];
            points[0] = new FCPoint(imageRect.left + 4, imageRect.top);
            points[1] = new FCPoint(imageRect.left, imageRect.top);
            points[2] = new FCPoint(imageRect.left, imageRect.bottom);
            points[3] = new FCPoint(imageRect.right, imageRect.bottom);
            points[4] = new FCPoint(imageRect.right, imageRect.top);
            points[5] = new FCPoint(imageRect.left + 18, imageRect.top);
            paint.drawPolyline(fillColor, 1, 0, points);
            drawText(paint, "xy", fillColor, new FCFont("Default", 10, true, false, false), imageRect.left + 4, imageRect.top - 8);
        }
        else if (cName.equals("LayoutDiv"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 6, imageRect.right - 1, imageRect.top + 6);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 1, imageRect.top + 12);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 18, imageRect.right - 1, imageRect.top + 18);
        }
        else if (cName.equals("TableLayoutDiv"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 1, imageRect.top + 12);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 11, imageRect.top, imageRect.left + 11, imageRect.bottom - 1);
        }
        else if (cName.equals("Spin"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            drawText(paint, "1", fillColor, new FCFont("Default", 10, true, false, false), imageRect.left + 2, imageRect.top);
            drawText(paint, "2", fillColor, new FCFont("Default", 10, true, false, false), imageRect.left + 2, imageRect.top + 10);
            if (true)
            {
                FCPoint[] points = new FCPoint[3];
                int mw = 10, mh = 10, dSize = 4;
                points[0] = new FCPoint(imageRect.left + 7 + mw, imageRect.top + mh - dSize - 2);
                points[1] = new FCPoint(imageRect.left + 7 + mw - dSize, imageRect.top + mh + dSize - 2);
                points[2] = new FCPoint(imageRect.left + 7 + mw + dSize, imageRect.top + mh + dSize - 2);
                paint.fillPolygon(fillColor, points);
            }
            if (true)
            {
                FCPoint[] points = new FCPoint[3];
                int mw = 10, mh = 10, dSize = 4;
                points[0] = new FCPoint(imageRect.left + 7 + mw, mh + imageRect.top + dSize + 10);
                points[1] = new FCPoint(imageRect.left + 7 + mw - dSize, imageRect.top + mh - dSize + 10);
                points[2] = new FCPoint(imageRect.left + 7 + mw + dSize, imageRect.top + mh - dSize + 10);
                paint.fillPolygon(fillColor, points);
            }
        }
        else if (cName.equals("TabView"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.left + 11, imageRect.top + 6));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 11, imageRect.top, imageRect.right, imageRect.top + 7));
        }
        else if (cName.equals("Window"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
            paint.drawLine(fillColor, 1, 0, imageRect.left + 3, imageRect.top + 11, imageRect.left + 9, imageRect.top + 11);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 3, imageRect.top + 17, imageRect.left + 9, imageRect.top + 17);
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 12, imageRect.top + 9, imageRect.left + 21, imageRect.top + 13));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 12, imageRect.top + 16, imageRect.left + 21, imageRect.top + 20));
        }
        else if (cName.equals("Tree"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 2, imageRect.top + 2, imageRect.left + 8, imageRect.top + 6));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 4, imageRect.top + 8, imageRect.left + 10, imageRect.top + 12));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 4, imageRect.top + 14, imageRect.left + 10, imageRect.top + 18));
            paint.drawRect(fillColor, 1, 0, new FCRect(imageRect.left + 4, imageRect.top + 20, imageRect.left + 10, imageRect.top + 24));
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top + 10, imageRect.left + 22, imageRect.top + 10);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top + 16, imageRect.left + 22, imageRect.top + 16);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top + 22, imageRect.left + 22, imageRect.top + 22);
        }
        else if (cName.equals("Chart"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            int pWidth = (imageRect.right - imageRect.left) / 3;
            paint.fillRect(fillColor, new FCRect(imageRect.left + 2, imageRect.top + 10, imageRect.left + pWidth, imageRect.bottom - 1));
            paint.fillRect(fillColor, new FCRect(imageRect.left + pWidth + 1, imageRect.top + 5, imageRect.left + pWidth * 2 - 1, imageRect.bottom - 1));
            paint.fillRect(fillColor, new FCRect(imageRect.left + pWidth * 2, imageRect.top + 10, imageRect.left + pWidth * 3 - 2, imageRect.bottom - 1));

        }
        else if (cName.equals("Custom"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            drawText(paint, "U", fillColor, new FCFont("Default", 20, true, false, false), imageRect.left + 1, imageRect.top);

        }
        else if (cName.equals("BandedGrid"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 11, imageRect.right - 2, imageRect.top + 11);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 16, imageRect.right - 2, imageRect.top + 16);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 6, imageRect.top, imageRect.left + 6, imageRect.bottom - 2);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 12, imageRect.top, imageRect.left + 12, imageRect.bottom - 2);
            paint.drawLine(fillColor, 1, 0, imageRect.left + 18, imageRect.top, imageRect.left + 18, imageRect.bottom - 2);
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top + 6, imageRect.right - 1, imageRect.top + 11));
        } else if (cName.equals("Menu"))
        {
            paint.drawRect(fillColor, 1, 0, imageRect);
            paint.fillRect(fillColor, new FCRect(imageRect.left, imageRect.top, imageRect.right - 1, imageRect.top + 6));
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 6, imageRect.right - 1, imageRect.top + 6);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 12, imageRect.right - 1, imageRect.top + 12);
            paint.drawLine(fillColor, 1, 0, imageRect.left, imageRect.top + 18, imageRect.right - 1, imageRect.top + 18);
        } else if (cName.equals("Paint"))
        {
            paint.drawEllipse(fillColor, 1, 0, imageRect);
        }
    }
}
